package com.bsoft.gol.hbs.dao;

import ctd.persistence.annotation.DAOMethod;
import ctd.persistence.annotation.DAOParam;
import ctd.persistence.support.hibernate.HibernateSupportDelegateDAO;
import ctd.persistence.support.hibernate.template.AbstractHibernateStatelessResultAction;
import ctd.persistence.support.hibernate.template.HibernateSessionTemplate;
import ctd.persistence.support.hibernate.template.HibernateStatelessResultAction;
import ctd.spring.boot.annotation.SsdevDao;
import ctd.util.converter.ConversionUtils;
import hc.ucenter.dto.UcUserBindResult;
import hcn.base.MsgPushTaskDetail;
import hcn.util.CommonUtils;
import java.math.BigInteger;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.atag.dao.util.CustomAliasToEntityMapResultTransformer;
import org.hibernate.Query;
import org.hibernate.StatelessSession;
import org.hibernate.transform.Transformers;
import pcn.bean.consultation.QueryMsgPushObjectQo;
import pcn.bean.consultation.QueryPushDoctorQo;
import pcn.bean.consultation.QueryPushPatientQo;
import pcn.vo.consultation.QueryPushDoctorVo;
import pcn.vo.consultation.QueryPushPatientVo;

/**
 * @description:手工消息推送任务执行详情表
 * @author: zhengcb10708
 * @create: 2021-09-01 16:25
 **/
@SsdevDao(serviceId = "msgPushTaskDetailService")
public abstract class MsgPushTaskDetailDao  extends HibernateSupportDelegateDAO<MsgPushTaskDetail> {
    public MsgPushTaskDetailDao() {
        this.setKeyField("id");
    }

    @DAOMethod(sql = "from MsgPushTaskDetail where id=:id")
    public abstract MsgPushTaskDetail getMsgPushTaskDetailById(@DAOParam("id") Long id);

    @DAOMethod(sql = "delete from MsgPushTaskDetail where msgPushTaskId=:msgPushTaskId")
    public abstract void deleteMsgPushTaskDetailByTaskId(@DAOParam("msgPushTaskId") Long msgPushTaskId);

    @DAOMethod(sql = "select count(1) from MsgPushTaskDetail where pushStatus=1 and msgPushTaskId=:msgPushTaskId  ")
    public abstract long getMsgPushTaskCount(@DAOParam("msgPushTaskId") Long msgPushTaskId);

    @DAOMethod(sql = "from MsgPushTaskDetail where  userId=:userId and msgPushTaskId=:msgPushTaskId ")
    public abstract List<MsgPushTaskDetail> findMsgPushTaskDetailList(@DAOParam("userId") String userId,
                                                                     @DAOParam("msgPushTaskId") Long msgPushTaskId);

    @DAOMethod(sql = "update MsgPushTaskDetail set successMsgType=:successMsgType ,failMsgType=:failMsgType, failReason=:failReason,pushStatus=:pushStatus,pushTime=:pushTime,lastModifyTime=:lastModifyTime where userId=:userId and msgPushTaskId=:msgPushTaskId ")
    public abstract void updateMsgPushTaskDetail(@DAOParam("successMsgType") String successMsgType,
                                                 @DAOParam("failMsgType") String failMsgType,
                                                 @DAOParam("failReason") String failReason,
                                                 @DAOParam("pushStatus") Byte pushStatus,
                                                 @DAOParam("pushTime") Timestamp pushTime,
                                                 @DAOParam("lastModifyTime") Timestamp lastModifyTime,
                                                 @DAOParam("userId") String userId,
                                                 @DAOParam("msgPushTaskId") Long msgPushTaskId);


//    public List<QueryPushPatientVo> queryPushPatientList(final QueryPushPatientQo queryPushPatientQo) {
//        HibernateStatelessResultAction<List<QueryPushPatientVo>> action =
//                new AbstractHibernateStatelessResultAction<List<QueryPushPatientVo>>() {
//                    @Override
//                    public void execute(StatelessSession ss) throws Exception {
//                        StringBuffer stringBuffer = new StringBuffer();
//                        stringBuffer.append(" SELECT userId,userName,patientName,patientIdentityCardType,patientIdentityCardNumber, ");
//                        stringBuffer.append(" patientMedicalCardType,patientMedicalCardNumber,mobile ");
//                        stringBuffer.append(" from ");
//                        stringBuffer.append(" ( SELECT DISTINCT c.idOrNo userId, b.personName userName, b.personName patientName, ");
//                        stringBuffer.append(" b.idCardType patientIdentityCardType,b.idCard patientIdentityCardNumber,a.idType patientMedicalCardType, ");
//                        stringBuffer.append(" a.idOrNo patientMedicalCardNumber,b.phoneNo mobile ");
//                        stringBuffer.append(" from mpi_identity a,mpi_demographicinfo b , mpi_identity c  ");
//                        stringBuffer.append(" where a.mpiId=b.mpiId and b.mpiId=c.mpiId and a.classify='01' and a.idType='02' and c.classify='03' and c.idType='01' ");
//                        stringBuffer.append(" and (SELECT count(1) from mpi_familymember t where t.masterId=a.mpiId or t.memberId=a.mpiId) = 0 ");
//                        stringBuffer.append(" union ");
//                        stringBuffer.append(" SELECT DISTINCT d.idOrNo userId, b.personName userName, b.personName patientName, ");
//                        stringBuffer.append(" b.idCardType patientIdentityCardType,b.idCard patientIdentityCardNumber,a.idType patientMedicalCardType,  ");
//                        stringBuffer.append(" a.idOrNo patientMedicalCardNumber,b.phoneNo mobile ");
//                        stringBuffer.append(" from mpi_identity a,mpi_demographicinfo b ,mpi_familymember c , mpi_identity d  ");
//                        stringBuffer.append(" where a.mpiId=b.mpiId and a.mpiId=c.masterId and c.masterId=d.mpiId   ");
//                        stringBuffer.append(" and a.classify='01' and a.idType='02' and d.classify='03' and d.idType='01' ");
//                        stringBuffer.append(" union ");
//                        stringBuffer.append(" SELECT DISTINCT e.idOrNo userId, d.personName userName, b.personName patientName, ");
//                        stringBuffer.append(" b.idCardType patientIdentityCardType,b.idCard patientIdentityCardNumber,a.idType patientMedicalCardType, ");
//                        stringBuffer.append(" a.idOrNo patientMedicalCardNumber,d.phoneNo mobile from mpi_identity a,mpi_demographicinfo b , ");
//                        stringBuffer.append(" mpi_familymember c, mpi_demographicinfo d, mpi_identity e where a.mpiId=b.mpiId and a.mpiId=c.memberId  ");
//                        stringBuffer.append(" and c.masterId=d.mpiId and c.masterId = e.mpiId and a.classify='01' and a.idType='02' and e.classify='03' ");
//                        stringBuffer.append(" and e.idType='01') t ");
//                        stringBuffer.append(" where 1=1 ");
//                        if (CommonUtils.isNotEmpty(queryPushPatientQo.getPatientName())) {
//                            stringBuffer.append( " and t.patientName  like :patientName "  );
//                        }
//                        if (CommonUtils.isNotEmpty(queryPushPatientQo.getMobile())) {
//                            stringBuffer.append( " and t.mobile =:mobile  "  );
//                        }
//                        if (CommonUtils.isNotEmpty(queryPushPatientQo.getPatientIdentityCardNumber())) {
//                            stringBuffer.append( " and t.patientIdentityCardNumber =:patientIdentityCardNumber  "  );
//                        }
//                        if (CommonUtils.isNotEmpty(queryPushPatientQo.getPatientMedicalCardNumber())){
//                            stringBuffer.append( " and t.patientMedicalCardNumber =:patientMedicalCardNumber "  );
//                        }
//                        stringBuffer.append(" ORDER BY t.patientName ");
//
//                        Query query = ss.createSQLQuery(stringBuffer.toString());
//                        if (CommonUtils.isNotEmpty(queryPushPatientQo.getPatientName())) {
//                            query.setParameter("patientName",  "%" + queryPushPatientQo.getPatientName() + "%");
//                        }
//                        if (CommonUtils.isNotEmpty(queryPushPatientQo.getMobile())) {
//                            query.setParameter("mobile",  queryPushPatientQo.getMobile());
//                        }
//                        if (CommonUtils.isNotEmpty(queryPushPatientQo.getPatientIdentityCardNumber())) {
//                            query.setParameter("patientIdentityCardNumber",  queryPushPatientQo.getPatientIdentityCardNumber());
//                        }
//                        if (CommonUtils.isNotEmpty(queryPushPatientQo.getPatientMedicalCardNumber())){
//                            query.setParameter("patientMedicalCardNumber",  queryPushPatientQo.getPatientMedicalCardNumber());
//                        }
//                        query.setResultTransformer(CustomAliasToEntityMapResultTransformer.INSTANCE);
//                        //分页
//                        int first = queryPushPatientQo.getPageNo() > 0 ? (queryPushPatientQo.getPageNo() - 1) * queryPushPatientQo.getPageSize() : 0;
//                        query.setFirstResult(first);
//                        query.setMaxResults(queryPushPatientQo.getPageSize());
//
//                        List<Map> list = query.list();
//                        List<QueryPushPatientVo> voList = new ArrayList<QueryPushPatientVo>();
//                        if (CommonUtils.isNotEmpty(list)) {
//                            for (Map map : list) {
//                                voList.add(ConversionUtils.convert(map, QueryPushPatientVo.class));
//                            }
//                        } else {
//                            voList = new ArrayList<>();
//                        }
//                        setResult(voList);
//                    }
//                };
//        HibernateSessionTemplate.instance().execute(action);
//        return action.getResult();
//    }
//    public BigInteger queryPushPatientListCount(final QueryPushPatientQo queryPushPatientQo) {
//        HibernateStatelessResultAction<BigInteger> action = new AbstractHibernateStatelessResultAction<BigInteger>() {
//            @Override
//            public void execute(StatelessSession ss) throws Exception {
//
//                StringBuffer stringBuffer = new StringBuffer();
//                stringBuffer.append(" SELECT count(1) from ");
//                stringBuffer.append(" ( SELECT DISTINCT c.idOrNo userId, b.personName userName, b.personName patientName, ");
//                stringBuffer.append(" b.idCardType patientIdentityCardType,b.idCard patientIdentityCardNumber,a.idType patientMedicalCardType, ");
//                stringBuffer.append(" a.idOrNo patientMedicalCardNumber,b.phoneNo mobile ");
//                stringBuffer.append(" from mpi_identity a,mpi_demographicinfo b , mpi_identity c  ");
//                stringBuffer.append(" where a.mpiId=b.mpiId and b.mpiId=c.mpiId and a.classify='01' and a.idType='02' and c.classify='03' and c.idType='01' ");
//                stringBuffer.append(" and (SELECT count(1) from mpi_familymember t where t.masterId=a.mpiId or t.memberId=a.mpiId) = 0 ");
//                stringBuffer.append(" union ");
//                stringBuffer.append(" SELECT DISTINCT d.idOrNo userId, b.personName userName, b.personName patientName, ");
//                stringBuffer.append(" b.idCardType patientIdentityCardType,b.idCard patientIdentityCardNumber,a.idType patientMedicalCardType,  ");
//                stringBuffer.append(" a.idOrNo patientMedicalCardNumber,b.phoneNo mobile ");
//                stringBuffer.append(" from mpi_identity a,mpi_demographicinfo b ,mpi_familymember c , mpi_identity d  ");
//                stringBuffer.append(" where a.mpiId=b.mpiId and a.mpiId=c.masterId and c.masterId=d.mpiId   ");
//                stringBuffer.append(" and a.classify='01' and a.idType='02' and d.classify='03' and d.idType='01' ");
//                stringBuffer.append(" union ");
//                stringBuffer.append(" SELECT DISTINCT e.idOrNo userId, d.personName userName, b.personName patientName, ");
//                stringBuffer.append(" b.idCardType patientIdentityCardType,b.idCard patientIdentityCardNumber,a.idType patientMedicalCardType, ");
//                stringBuffer.append(" a.idOrNo patientMedicalCardNumber,d.phoneNo mobile from mpi_identity a,mpi_demographicinfo b , ");
//                stringBuffer.append(" mpi_familymember c, mpi_demographicinfo d, mpi_identity e where a.mpiId=b.mpiId and a.mpiId=c.memberId  ");
//                stringBuffer.append(" and c.masterId=d.mpiId and c.masterId = e.mpiId and a.classify='01' and a.idType='02' and e.classify='03' ");
//                stringBuffer.append(" and e.idType='01') t ");
//                stringBuffer.append(" where 1=1 ");
//                if (CommonUtils.isNotEmpty(queryPushPatientQo.getPatientName())) {
//                    stringBuffer.append( " and t.patientName  like :patientName "  );
//                }
//                if (CommonUtils.isNotEmpty(queryPushPatientQo.getMobile())) {
//                    stringBuffer.append( " and t.mobile =:mobile  "  );
//                }
//                if (CommonUtils.isNotEmpty(queryPushPatientQo.getPatientIdentityCardNumber())) {
//                    stringBuffer.append( " and t.patientIdentityCardNumber =:patientIdentityCardNumber  "  );
//                }
//                if (CommonUtils.isNotEmpty(queryPushPatientQo.getPatientMedicalCardNumber())){
//                    stringBuffer.append( " and t.patientMedicalCardNumber =:patientMedicalCardNumber "  );
//                }
//                Query query = ss.createSQLQuery(stringBuffer.toString());
//                if (CommonUtils.isNotEmpty(queryPushPatientQo.getPatientName())) {
//                    query.setParameter("patientName",  "%" + queryPushPatientQo.getPatientName() + "%");
//                }
//                if (CommonUtils.isNotEmpty(queryPushPatientQo.getMobile())) {
//                    query.setParameter("mobile",  queryPushPatientQo.getMobile());
//                }
//                if (CommonUtils.isNotEmpty(queryPushPatientQo.getPatientIdentityCardNumber())) {
//                    query.setParameter("patientIdentityCardNumber",  queryPushPatientQo.getPatientIdentityCardNumber());
//                }
//                if (CommonUtils.isNotEmpty(queryPushPatientQo.getPatientMedicalCardNumber())){
//                    query.setParameter("patientMedicalCardNumber",  queryPushPatientQo.getPatientMedicalCardNumber());
//                }
//                List list = query.list();
//                if (list.size() == 1) {
//                    Object o = list.get(0);
//                    BigInteger count = (BigInteger) o;
//                    setResult(count);
//                }
//            }
//        };
//        HibernateSessionTemplate.instance().execute(action);
//        return action.getResult();
//    }

//    public List<QueryPushDoctorVo> queryPushDoctorList(final QueryPushDoctorQo queryPushDoctorQo,final List<String> departmentList) {
//        HibernateStatelessResultAction<List<QueryPushDoctorVo>> action =
//                new AbstractHibernateStatelessResultAction<List<QueryPushDoctorVo>>() {
//                    @Override
//                    public void execute(StatelessSession ss) throws Exception {
//                        StringBuffer stringBuffer = new StringBuffer();
//                        stringBuffer.append(" SELECT c.idOrNo userId,a.name userName,a.phoneNo mobile,b.localDoctorId jobName, ");
//                        stringBuffer.append(" d.localOrgId organizationCode,d.fullName organizationName , ");
//                        stringBuffer.append(" e.localDeptId departmentCode,e.name departmentName ");
//                        stringBuffer.append(" from doct_info a ,base_orgdoctors b ,doc_identity c,base_orgmain d ,base_deptmain e  ");
//                        stringBuffer.append(" where a.doctorId=b.doctorId and a.doctorId=c.doctorId and b.orgId=d.orgId and b.deptId=e.deptId  ");
//                        stringBuffer.append(" and b.mainFlag='1' and a.status='1' ");
//
//                        if (CommonUtils.isNotEmpty(queryPushDoctorQo.getDoctorName())) {
//                            stringBuffer.append( " and a.name like :doctorName  "  );
//                        }
//                        if (CommonUtils.isNotEmpty(queryPushDoctorQo.getOrganizationName())) {
//                            stringBuffer.append( " and d.fullName like :organizationName  "  );
//                        }
//                        if (CommonUtils.isNotEmpty(departmentList)) {
//                            stringBuffer.append( " and e.localDeptId in (:departmentList) "  );
//                        }
//                        if (CommonUtils.isNotEmpty(queryPushDoctorQo.getMobile())){
//                            stringBuffer.append( " and a.phoneNo =:mobile "  );
//                        }
//                        if (CommonUtils.isNotEmpty(queryPushDoctorQo.getJobName())){
//                            stringBuffer.append( " and b.localDoctorId =:jobName "  );
//                        }
//                        stringBuffer.append("  ORDER BY a.name desc ,a.createDt desc ");
//
//                        Query query = ss.createSQLQuery(stringBuffer.toString());
//
//                        if (CommonUtils.isNotEmpty(queryPushDoctorQo.getDoctorName())) {
//                            query.setParameter("doctorName",  "%" + queryPushDoctorQo.getDoctorName() + "%");
//                        }
//                        if (CommonUtils.isNotEmpty(queryPushDoctorQo.getOrganizationName())) {
//                            query.setParameter("organizationName",  "%" + queryPushDoctorQo.getOrganizationName() + "%");
//                        }
//                        if (CommonUtils.isNotEmpty(departmentList)) {
//                            query.setParameterList("departmentList",departmentList);
//                        }
//                        if (CommonUtils.isNotEmpty(queryPushDoctorQo.getMobile())){
//                            query.setParameter("mobile",  queryPushDoctorQo.getMobile());
//                        }
//                        if (CommonUtils.isNotEmpty(queryPushDoctorQo.getJobName())){
//                            query.setParameter("jobName",  queryPushDoctorQo.getJobName());
//                        }
//
//                        query.setResultTransformer(CustomAliasToEntityMapResultTransformer.INSTANCE);
//                        //分页
//                        int first = queryPushDoctorQo.getPageNo() > 0 ? (queryPushDoctorQo.getPageNo() - 1) * queryPushDoctorQo.getPageSize() : 0;
//                        query.setFirstResult(first);
//                        query.setMaxResults(queryPushDoctorQo.getPageSize());
//
//                        List<Map> list = query.list();
//                        List<QueryPushDoctorVo> voList = new ArrayList<QueryPushDoctorVo>();
//                        if (CommonUtils.isNotEmpty(list)) {
//                            for (Map map : list) {
//                                voList.add(ConversionUtils.convert(map, QueryPushDoctorVo.class));
//                            }
//                        } else {
//                            voList = new ArrayList<>();
//                        }
//                        setResult(voList);
//                    }
//                };
//        HibernateSessionTemplate.instance().execute(action);
//        return action.getResult();
//    }

//    public BigInteger queryPushDoctorListCount(final QueryPushDoctorQo queryPushDoctorQo,final List<String> departmentList) {
//        HibernateStatelessResultAction<BigInteger> action = new AbstractHibernateStatelessResultAction<BigInteger>() {
//            @Override
//            public void execute(StatelessSession ss) throws Exception {
//
//                StringBuffer stringBuffer = new StringBuffer();
//                stringBuffer.append(" select count(1) from doct_info a ,base_orgdoctors b ,doc_identity c,base_orgmain d ,base_deptmain e  ");
//                stringBuffer.append(" where a.doctorId=b.doctorId and a.doctorId=c.doctorId and b.orgId=d.orgId and b.deptId=e.deptId  ");
//                stringBuffer.append(" and b.mainFlag='1' and a.status='1' ");
//
//                if (CommonUtils.isNotEmpty(queryPushDoctorQo.getDoctorName())) {
//                    stringBuffer.append( " and a.name like :doctorName  "  );
//                }
//                if (CommonUtils.isNotEmpty(queryPushDoctorQo.getOrganizationName())) {
//                    stringBuffer.append( " and d.fullName like :organizationName  "  );
//                }
//                if (CommonUtils.isNotEmpty(departmentList)) {
//                    stringBuffer.append(" and e.localDeptId in (:departmentList) ");
//                }
//                if (CommonUtils.isNotEmpty(queryPushDoctorQo.getMobile())){
//                    stringBuffer.append( " and a.phoneNo =:mobile "  );
//                }
//                if (CommonUtils.isNotEmpty(queryPushDoctorQo.getJobName())){
//                    stringBuffer.append( " and b.localDoctorId =:jobName "  );
//                }
//                stringBuffer.append("  ORDER BY a.name desc ,a.createDt desc ");
//
//                Query query = ss.createSQLQuery(stringBuffer.toString());
//
//                if (CommonUtils.isNotEmpty(queryPushDoctorQo.getDoctorName())) {
//                    query.setParameter("doctorName",  "%" + queryPushDoctorQo.getDoctorName() + "%");
//                }
//                if (CommonUtils.isNotEmpty(queryPushDoctorQo.getOrganizationName())) {
//                    query.setParameter("organizationName",  "%" + queryPushDoctorQo.getOrganizationName() + "%");
//                }
//                if (CommonUtils.isNotEmpty(departmentList)) {
//                    query.setParameterList("departmentList",  departmentList);
//                }
//                if (CommonUtils.isNotEmpty(queryPushDoctorQo.getMobile())){
//                    query.setParameter("mobile",  queryPushDoctorQo.getMobile());
//                }
//                if (CommonUtils.isNotEmpty(queryPushDoctorQo.getJobName())){
//                    query.setParameter("jobName",  queryPushDoctorQo.getJobName());
//                }
//
//                List list = query.list();
//                if (list.size() == 1) {
//                    Object o = list.get(0);
//                    BigInteger count = (BigInteger) o;
//                    setResult(count);
//                }
//            }
//        };
//        HibernateSessionTemplate.instance().execute(action);
//        return action.getResult();
//    }

//    public List<MsgPushTaskDetail> queryMsgPushObjectList(final QueryMsgPushObjectQo queryMsgPushObjectQo,final List<String> departmentCodeList) {
//        HibernateStatelessResultAction<List<MsgPushTaskDetail>> action =
//                new AbstractHibernateStatelessResultAction<List<MsgPushTaskDetail>>() {
//                    @Override
//                    public void execute(StatelessSession ss) throws Exception {
//                        StringBuffer stringBuffer = new StringBuffer();
//                        stringBuffer.append(" SELECT a.msg_push_task_id msgPushTaskId,a.user_id userId,a.user_name userName,a.patient_name patientName, ");
//                        stringBuffer.append(" a.patient_medical_card_type patientMedicalCardType,a.patient_medical_card_number patientMedicalCardNumber, ");
//                        stringBuffer.append(" a.patient_identity_card_type patientIdentityCardType,a.patient_identity_card_number patientIdentityCardNumber, ");
//                        stringBuffer.append(" a.mobile,a.job_name jobName,a.organization_code organizationCode,a.organization_name organizationName, ");
//                        stringBuffer.append(" a.department_code departmentCode,a.department_name departmentName, ");
//                        stringBuffer.append(" a.create_time createTime,a.last_modify_time lastModifyTime,a.push_time pushTime,a.msg_type msgType, ");
//                        stringBuffer.append(" a.success_msg_type successMsgType,a.fail_msg_type failMsgType,a.fail_reason failReason,a.push_status pushStatus ");
//                        stringBuffer.append(" from msg_push_task_detail a ");
//                        stringBuffer.append(" where 1=1 ");
//                        if (CommonUtils.isNotEmpty(queryMsgPushObjectQo.getUserName())) {
//                            stringBuffer.append( " and a.user_name like  :userName  "  );
//                        }
//                        if (CommonUtils.isNotEmpty(queryMsgPushObjectQo.getPatientName())) {
//                            stringBuffer.append( " and a.patient_name like :patientName  "  );
//                        }
//                        if (CommonUtils.isNotEmpty(queryMsgPushObjectQo.getPatientIdentityCardNumber())) {
//                            stringBuffer.append( " and a.patient_identity_card_number =:patientIdentityCardNumber  "  );
//                        }
//                        if (CommonUtils.isNotEmpty(queryMsgPushObjectQo.getPatientMedicalCardNumber())){
//                            stringBuffer.append( " and a.patient_medical_card_number =:patientMedicalCardNumber "  );
//                        }
//                        if (CommonUtils.isNotEmpty(queryMsgPushObjectQo.getMobile())){
//                            stringBuffer.append( " and a.mobile =:mobile "  );
//                        }
//                        if (CommonUtils.isNotEmpty(queryMsgPushObjectQo.getJobName())){
//                            stringBuffer.append( " and a.job_name =:jobName "  );
//                        }
//                        if (CommonUtils.isNotEmpty(queryMsgPushObjectQo.getOrganizationCode())) {
//                            stringBuffer.append( " and a.organization_code =:organizationCode   "  );
//                        }
//                        if (CommonUtils.isNotEmpty(departmentCodeList)) {
//                            stringBuffer.append( " and a.department_code in (:departmentCodeList)  "  );
//                        }
//                        if (CommonUtils.isNotEmpty(queryMsgPushObjectQo.getPushStatus())&&queryMsgPushObjectQo.getPushStatus()!=99) {
//                            stringBuffer.append( " and a.push_status =:pushStatus   "  );
//                        }
//                        if (CommonUtils.isNotEmpty(queryMsgPushObjectQo.getMsgPushTaskId())) {
//                            stringBuffer.append( " and a.msg_push_task_id =:msgPushTaskId   "  );
//                        }
//                        stringBuffer.append("  ORDER BY a.id ");
//
//                        Query query = ss.createSQLQuery(stringBuffer.toString());
//                        if (CommonUtils.isNotEmpty(queryMsgPushObjectQo.getUserName())) {
//                            query.setParameter("userName",  "%" + queryMsgPushObjectQo.getUserName() + "%");
//                        }
//                        if (CommonUtils.isNotEmpty(queryMsgPushObjectQo.getPatientName())) {
//                            query.setParameter("patientName",  "%" + queryMsgPushObjectQo.getPatientName() + "%");
//                        }
//                        if (CommonUtils.isNotEmpty(queryMsgPushObjectQo.getPatientIdentityCardNumber())) {
//                            query.setParameter("patientIdentityCardNumber",  queryMsgPushObjectQo.getPatientIdentityCardNumber());
//                        }
//                        if (CommonUtils.isNotEmpty(queryMsgPushObjectQo.getPatientMedicalCardNumber())){
//                            query.setParameter("patientMedicalCardNumber",  queryMsgPushObjectQo.getPatientMedicalCardNumber());
//                        }
//                        if (CommonUtils.isNotEmpty(queryMsgPushObjectQo.getMobile())){
//                            query.setParameter("mobile",  queryMsgPushObjectQo.getMobile());
//                        }
//                        if (CommonUtils.isNotEmpty(queryMsgPushObjectQo.getJobName())){
//                            query.setParameter("jobName",  queryMsgPushObjectQo.getJobName());
//                        }
//                        if (CommonUtils.isNotEmpty(queryMsgPushObjectQo.getOrganizationCode())) {
//                            query.setParameter("organizationCode",queryMsgPushObjectQo.getOrganizationCode());
//                        }
//                        if (CommonUtils.isNotEmpty(departmentCodeList)) {
//                            query.setParameterList("departmentCodeList",departmentCodeList);
//                        }
//                        if (CommonUtils.isNotEmpty(queryMsgPushObjectQo.getPushStatus())&&queryMsgPushObjectQo.getPushStatus()!=99) {
//                            query.setParameter("pushStatus",queryMsgPushObjectQo.getPushStatus());
//                        }
//                        if (CommonUtils.isNotEmpty(queryMsgPushObjectQo.getMsgPushTaskId())) {
//                            query.setParameter("msgPushTaskId",queryMsgPushObjectQo.getMsgPushTaskId());
//                        }
//
//                        query.setResultTransformer(CustomAliasToEntityMapResultTransformer.INSTANCE);
//                        //分页
//                        int first = queryMsgPushObjectQo.getPageNo() > 0 ? (queryMsgPushObjectQo.getPageNo() - 1) * queryMsgPushObjectQo.getPageSize() : 0;
//                        query.setFirstResult(first);
//                        query.setMaxResults(queryMsgPushObjectQo.getPageSize());
//
//                        List<Map> list = query.list();
//                        List<MsgPushTaskDetail> voList = new ArrayList<MsgPushTaskDetail>();
//                        if (CommonUtils.isNotEmpty(list)) {
//                            for (Map map : list) {
//                                voList.add(ConversionUtils.convert(map, MsgPushTaskDetail.class));
//                            }
//                        } else {
//                            voList = new ArrayList<>();
//                        }
//                        setResult(voList);
//                    }
//                };
//        HibernateSessionTemplate.instance().execute(action);
//        return action.getResult();
//    }
    public BigInteger queryMsgPushObjectListCount(final QueryMsgPushObjectQo queryMsgPushObjectQo,final List<String> departmentCodeList) {
        HibernateStatelessResultAction<BigInteger> action = new AbstractHibernateStatelessResultAction<BigInteger>() {
            @Override
            public void execute(StatelessSession ss) throws Exception {

                StringBuffer stringBuffer = new StringBuffer();
                stringBuffer.append(" select count(1) from msg_push_task_detail a ");
                stringBuffer.append(" where 1=1 ");
                if (CommonUtils.isNotEmpty(queryMsgPushObjectQo.getUserName())) {
                    stringBuffer.append( " and a.user_name like  :userName  "  );
                }
                if (CommonUtils.isNotEmpty(queryMsgPushObjectQo.getPatientName())) {
                    stringBuffer.append( " and a.patient_name like :patientName  "  );
                }
                if (CommonUtils.isNotEmpty(queryMsgPushObjectQo.getPatientIdentityCardNumber())) {
                    stringBuffer.append( " and a.patient_identity_card_number =:patientIdentityCardNumber  "  );
                }
                if (CommonUtils.isNotEmpty(queryMsgPushObjectQo.getPatientMedicalCardNumber())){
                    stringBuffer.append( " and a.patient_medical_card_number =:patientMedicalCardNumber "  );
                }
                if (CommonUtils.isNotEmpty(queryMsgPushObjectQo.getMobile())){
                    stringBuffer.append( " and a.mobile =:mobile "  );
                }
                if (CommonUtils.isNotEmpty(queryMsgPushObjectQo.getJobName())){
                    stringBuffer.append( " and a.job_name =:jobName "  );
                }
                if (CommonUtils.isNotEmpty(queryMsgPushObjectQo.getOrganizationCode())) {
                    stringBuffer.append( " and a.organization_code =:organizationCode   "  );
                }
                if (CommonUtils.isNotEmpty(departmentCodeList)) {
                    stringBuffer.append( " and a.department_code in (:departmentCodeList)  "  );
                }
                if (CommonUtils.isNotEmpty(queryMsgPushObjectQo.getPushStatus())&&queryMsgPushObjectQo.getPushStatus()!=99) {
                    stringBuffer.append( " and a.push_status =:pushStatus   "  );
                }
                if (CommonUtils.isNotEmpty(queryMsgPushObjectQo.getMsgPushTaskId())) {
                    stringBuffer.append( " and a.msg_push_task_id =:msgPushTaskId   "  );
                }
                stringBuffer.append("  ORDER BY a.id ");

                Query query = ss.createSQLQuery(stringBuffer.toString());
                if (CommonUtils.isNotEmpty(queryMsgPushObjectQo.getUserName())) {
                    query.setParameter("userName",  "%" + queryMsgPushObjectQo.getUserName() + "%");
                }
                if (CommonUtils.isNotEmpty(queryMsgPushObjectQo.getPatientName())) {
                    query.setParameter("patientName",  "%" + queryMsgPushObjectQo.getPatientName() + "%");
                }
                if (CommonUtils.isNotEmpty(queryMsgPushObjectQo.getPatientIdentityCardNumber())) {
                    query.setParameter("patientIdentityCardNumber",  queryMsgPushObjectQo.getPatientIdentityCardNumber());
                }
                if (CommonUtils.isNotEmpty(queryMsgPushObjectQo.getPatientMedicalCardNumber())){
                    query.setParameter("patientMedicalCardNumber",  queryMsgPushObjectQo.getPatientMedicalCardNumber());
                }
                if (CommonUtils.isNotEmpty(queryMsgPushObjectQo.getMobile())){
                    query.setParameter("mobile",  queryMsgPushObjectQo.getMobile());
                }
                if (CommonUtils.isNotEmpty(queryMsgPushObjectQo.getJobName())){
                    query.setParameter("jobName",  queryMsgPushObjectQo.getJobName());
                }
                if (CommonUtils.isNotEmpty(queryMsgPushObjectQo.getOrganizationCode())) {
                    query.setParameter("organizationCode",queryMsgPushObjectQo.getOrganizationCode());
                }
                if (CommonUtils.isNotEmpty(departmentCodeList)) {
                    query.setParameterList("departmentCodeList",departmentCodeList);
                }
                if (CommonUtils.isNotEmpty(queryMsgPushObjectQo.getPushStatus())&&queryMsgPushObjectQo.getPushStatus()!=99) {
                    query.setParameter("pushStatus",queryMsgPushObjectQo.getPushStatus());
                }
                if (CommonUtils.isNotEmpty(queryMsgPushObjectQo.getMsgPushTaskId())) {
                    query.setParameter("msgPushTaskId",queryMsgPushObjectQo.getMsgPushTaskId());
                }
                List list = query.list();
                if (list.size() == 1) {
                    Object o = list.get(0);
                    BigInteger count = (BigInteger) o;
                    setResult(count);
                }
            }
        };
        HibernateSessionTemplate.instance().execute(action);
        return action.getResult();
    }

    public List<String> queryMsgPushList(final long msgPushTaskId) {
        HibernateStatelessResultAction<List<String>> action =
                new AbstractHibernateStatelessResultAction<List<String>>() {
                    @Override
                    public void execute(StatelessSession ss) throws Exception {
                        StringBuffer stringBuffer = new StringBuffer();
                        stringBuffer.append(" SELECT distinct a.user_id from msg_push_task_detail a  ");
                        stringBuffer.append(" where a.push_status in(0,2) and a.msg_push_task_id =:msgPushTaskId ");

                        Query query = ss.createSQLQuery(stringBuffer.toString());
                        query.setParameter("msgPushTaskId",msgPushTaskId);

                        List list = query.list();
                        List<String> voList;
                        if(CommonUtils.isNotEmpty(list)){
                            voList=list;
                        }else{
                            voList=new ArrayList<>();
                        }
                        setResult(voList);
                    }
                };
        HibernateSessionTemplate.instance().execute(action);
        return action.getResult();
    }

    public List<UcUserBindResult> getByUidAndTypeAndAppId(String userId, String bindType,String wxMpAppId) {
        HibernateStatelessResultAction<List<UcUserBindResult>> action =
                new AbstractHibernateStatelessResultAction<List<UcUserBindResult>>() {
                    @Override
                    public void execute(StatelessSession ss) throws Exception {
                        StringBuffer stringBuffer = new StringBuffer();
                        stringBuffer.append(" SELECT a.bind_id bindId,a.uid,a.bind_type bindType,a.bind_app_id bindAppId, ");
                        stringBuffer.append(" a.out_uid outUid ,a.bind_status bindStatus ");
                        stringBuffer.append(" from uc_user_bind a ");
                        stringBuffer.append(" where  1=1 ");
                        if(CommonUtils.isNotEmpty(userId)){
                            stringBuffer.append(" and a.uid =:userId ");
                        }
                        if(CommonUtils.isNotEmpty(bindType)){
                            stringBuffer.append(" and a.bind_type=:bindType ");
                        }
                        if(CommonUtils.isNotEmpty(wxMpAppId)){
                            stringBuffer.append(" and a.bind_app_id=:wxMpAppId ");
                        }
                        Query query = ss.createSQLQuery(stringBuffer.toString());
                        if(CommonUtils.isNotEmpty(userId)){
                            query.setParameter("userId",userId);
                        }
                        if(CommonUtils.isNotEmpty(bindType)){
                            query.setParameter("bindType",bindType);
                        }
                        if(CommonUtils.isNotEmpty(wxMpAppId)){
                            query.setParameter("wxMpAppId",wxMpAppId);
                        }
                        query.setResultTransformer(CustomAliasToEntityMapResultTransformer.INSTANCE);

                        List<Map> list = query.list();
                        List<UcUserBindResult> voList = new ArrayList<UcUserBindResult>();
                        if (CommonUtils.isNotEmpty(list)) {
                            for (Map map : list) {
                                voList.add(ConversionUtils.convert(map, UcUserBindResult.class));
                            }
                        } else {
                            voList = new ArrayList<>();
                        }
                        setResult(voList);
                    }
                };
        HibernateSessionTemplate.instance().execute(action);
        return action.getResult();
    }

}
